package com.coocaa.ops.admin.v1.dict;

import com.coocaa.ops.admin.base.annotation.Auth;
import com.coocaa.ops.admin.base.controller.MgrBaseController;
import com.coocaa.ops.admin.v1.dict.constant.DictCategoryConstants;
import com.coocaa.ops.admin.v1.dict.convert.DictQueryConverter;
import com.coocaa.ops.admin.v1.dict.service.DictInfoQueryServiceImpl;
import com.coocaa.ops.common.core.base.enums.AuthEnum;
import com.coocaa.ops.common.core.biz.dict.entity.DictInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author : hql
 * @date : 2020/2/24 15:23
 * @description
 */
@RestController
@RequestMapping("/v1/dict")
public class DictInfoController extends MgrBaseController {

    @Autowired
    private DictInfoQueryServiceImpl dictInfoQueryService;

    @Auth(verifyAuthority = true, authorityType = AuthEnum.BROWSER)
    @RequestMapping(value = "/getTypes/businessType",method = {RequestMethod.GET,RequestMethod.POST})
    public Object getTypes(HttpServletRequest request, Integer filter) {
        List<DictInfoEntity> types = dictInfoQueryService.queryByCategory(DictCategoryConstants.BUSINESS_TYPE);
        types = DictQueryConverter.handleBusinessType(request, types, filter);
        return render2Json(types);
    }

    /**
     * 根据路径参数type 获取类别
     */
    @RequestMapping(value = "/getTypes/{type}",method = {RequestMethod.GET,RequestMethod.POST})
    public Object getTypes(@PathVariable(value = "type") String type) {
        List<DictInfoEntity> types = dictInfoQueryService.queryByCategory(type);
        return render2Json(types);
    }


}
